package com.shhic.hhplt.server.model;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * 电子公示板信息对象
 * @author user
 *
 */
public class DashboardInfo {
	private long id=0;	//流水ID，每次新增后更新此值，用于客户端判定，如果为0，表示空
	private String dashboardName;	//公示板名（全局唯一）
	private String updateTime;	//更新时间
	private List<DashboardInfoItem> infoItemList;	//信息条目列表
	public String getDashboardName() {
		return dashboardName;
	}
	public void setDashboardName(String dashboardName) {
		this.dashboardName = dashboardName;
	}
	public String getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}
	public List<DashboardInfoItem> getInfoItemList() {
		return infoItemList;
	}
	public void setInfoItemList(List<DashboardInfoItem> infoItemList) {
		this.infoItemList = infoItemList;
	}
	public void setId(long id) {
		this.id = id;
	}
	public long getId() {
		return id;
	}
	
	/**
	 * 从字符串设置infoItemList
	 * @param infoItemListStr	字符串格式：键:值,……
	 */
	public void setInfoItemListStr(String infoItemListStr){
		infoItemList = new LinkedList<DashboardInfoItem>();
		String[] split = infoItemListStr.split(",");
		for(String kv : split){
			String[] kvv = kv.split(":");
			if(kvv.length == 2){
				infoItemList.add(new DashboardInfoItem(kvv[0],kvv[1]));
			}
		}
	}
	
	/**
	 * 构造一个空的信息对象
	 * @return
	 */
	public static DashboardInfo emptyDashboardInfo(String dashboardName) {
		DashboardInfo d = new DashboardInfo();
		d.setDashboardName(dashboardName);
		d.setUpdateTimeToNow();
		return d;
	}
	/**
	 * 设置更新时间为当前
	 */
	public void setUpdateTimeToNow() {
		setUpdateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
	}
}
